package org.yh.api.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

@RestController
public class MemberApiController {

	@Value("${server.port}")
	private String serverport;

	@RequestMapping("api/member")
	public String getMember() {
		System.out.println("member,线程名：" + Thread.currentThread().getName());
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "这个是member服务接口！端口号:" + serverport;
	}

	@RequestMapping("api/memberHystrix")
	@HystrixCommand(fallbackMethod = "errorMethod")
	public String getMemberHystrix() {
		System.out.println("memberHystrix,线程名：" + Thread.currentThread().getName());
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		return "这个是Hystrix服务接口！端口号:" + serverport;
	}

	// 服务降级方法
	public String errorMethod() {
		return "连接超时，请等待！";
	}

}
